package com.eden.util;

import com.eden.entity.BasisInfo;
import com.eden.entity.ResultJson;

/**
 * ClassName: Generator
 * Package: com.eden.util
 * Description: todo
 * Date:  2020/10/19 11:04
 *
 * @Author: 李秉林
 */
public class Generator {
	//路径信息
	public static final String ENTITY="entity";
	public static final String MAPPER="mapper";
	public static final String MAPPERXML="mapperXML";
	public static final String SERVICE="service";
	public static final String CONTROLLER="controller";
	
	// 创建实体类
	public static ResultJson createEntity(String url, BasisInfo bi) {
		String fileUrl= PathUtil.getGeneratorFileUrl(url, bi.getEntityUrl(), bi.getEntityName(), ENTITY);
		return FreemarkerUtil.createFile(bi, "entity.ftl", fileUrl);
	}
	
	// 创建mapper
	public static ResultJson createMapper(String url, BasisInfo bi) {
		String fileUrl= PathUtil.getGeneratorFileUrl(url, bi.getMapperUrl(), bi.getMapperName(), MAPPER);
		return FreemarkerUtil.createFile(bi, "mapper.ftl", fileUrl);
	}
	
	// 创建mapperXML
	public static ResultJson createMapperXML(String url, BasisInfo bi) {
		String fileUrl= PathUtil.getGeneratorFileUrl(url, bi.getMapperXmlUrl(), bi.getMapperXmlName(), MAPPERXML);
		return FreemarkerUtil.createFile(bi, "mapperXML.ftl", fileUrl);
	}
	
	// 创建service
	public static ResultJson createService(String url, BasisInfo bi) {
		String fileUrl= PathUtil.getGeneratorFileUrl(url, bi.getServiceUrl(), bi.getServiceName(), SERVICE);
		return FreemarkerUtil.createFile(bi, "service.ftl", fileUrl);
	}
	
	// 创建controller
	public static ResultJson createController(String url, BasisInfo bi) {
		String fileUrl= PathUtil.getGeneratorFileUrl(url, bi.getControllerUrl(), bi.getControllerName(), CONTROLLER);
		return FreemarkerUtil.createFile(bi, "controller.ftl", fileUrl);
	}
}
